package cn.wolfcode.crm.domain;

import cn.wolfcode.crm.util.DateUtil;
import cn.wolfcode.crm.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//跟进历史
@Setter@Getter
public class CustomerTraceHistory extends BaseDomain {
    public static final Integer traceResult_GOOD = 3; //优
    public static final Integer traceResult_NORMAL = 2; //中
    public static final Integer traceResult_BAD = 1; //差

    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date traceTime; //跟进时间

    private String traceDetails; //跟进内容

    private SystemDictionaryItem traceType; //实施方式

    private Integer traceResult = traceResult_NORMAL; //跟进结果

    private String remark; //备注

    private Customer customer; //客户

    private Employee inputUser; //录入人

    private Date inputTime; //录入时间

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("traceTime", DateUtil.formatDate(traceTime));
        map.put("traceTypeId", traceType.getId());
        map.put("traceDetails", traceDetails);
        map.put("traceResult", traceResult);
        map.put("remark", remark);
        map.put("customerName", customer.getName());
        return JSONUtil.toJSONString(map);
    }

    public String getTraceResultName() {
        String msg = "中";
        if (traceResult == traceResult_GOOD) {
            msg = "优";
        } else if (traceResult == traceResult_BAD) {
            msg = "差";
        }
        return msg;
    }
}